#include "bullet.h"
#include "config.h"
#include "tool.h"
#include <QtDebug>
Bullet::Bullet(Tower *parent)
{
    this->IfDelete=false;
    this->_mPix.load(":/pictures/bullet/bullet1.png");
    this->width=BULLET_WIDTH;
    this->height=BULLET_WIDTH;
    this->Position_X=parent->GetX();
    this->Position_Y=parent->GetY();
    this->velocity=BULLET_VELOCITY;
    this->damage=ATTACKER2_HEIGHT;
    float angle = parent->GetAngle() + int(qrand()%360 - 180)/18;
    direction_x = Tool::angel_to_vector(angle).x()*(this->velocity/50);
    direction_y = Tool::angel_to_vector(angle).y()*(this->velocity/50);
    this->_mRect.setRect(this->Position_X,this->Position_Y,this->width,this->height);
}

void Bullet::UpdataPosition()
{
    this->Position_X+=this->direction_x;
    this->Position_Y+=this->direction_y;
    this->_mRect.moveTo(this->Position_X,this->Position_Y);
}

bool Bullet::CheckPosition()
{
    if(this->Position_X<0||this->Position_X>1380){
        return false;
    }
    if(this->Position_Y<0||this->Position_Y>700){
        return false;
    }
    return true;
}

float Bullet::GetX()
{
    return this->Position_X;
}

float Bullet::GetY()
{
    return this->Position_Y;
}

int Bullet::GetWidth()
{
    return this->width;
}

int Bullet::GetHeight()
{
    return this->height;
}

QPixmap &Bullet::GetPix()
{
    return this->_mPix;
}

QRect Bullet::GetRect()
{
    return this->_mRect;
}

int Bullet::GetDamage()
{
    return this->damage;
}

void Bullet::SetDelete()
{
    this->IfDelete=true;
}

bool Bullet::GetDelete()
{
    return this->IfDelete;
}

Bullet::~Bullet()
{
    qDebug()<<"delete bullet"<<endl;
}
